package labox.innovation.loginserver.gameserverpackets;

import labox.innovation.loginserver.GameServerTable;
import labox.innovation.loginserver.GameServerTable.GameServerInfo;

/**
 * 处理游戏服务器发来的服务器状态
 *
 */
public final class ServerStatus extends ClientBasePacket {

	public static final String[] STATUS_STRING = { "Down", "Good", "Normal", "Full", "Gm Only" };
	

	/*-----------------------服务器类型部分-------------------------------*/
	public static final int SERVER_LIST_CLOCK = 0x02;

	public static final int SERVER_LIST_SQUARE_BRACKET = 0x03;

	public static final int TEST_SERVER = 0x04;
	
	public static final int ON = 0x01;

	public static final int OFF = 0x00;
	
	/*-----------------------服务器状态部分-------------------------------*/
	
	public static final int SERVER_LIST_STATUS = 0x01;

	public static final int STATUS_DOWN = 0x00;

	public static final int STATUS_GOOD = 0x01;

	public static final int STATUS_NORMAL = 0x02;

	public static final int STATUS_FULL = 0x03;

	public static final int STATUS_GM_ONLY = 0x04;
	
	/*-----------------------服务器状推荐部分-------------------------------*/

	public static final int SERVER_LIST_TYPE = 0x05;

	public static final int TYPE_NORMAL = 0x00;

	public static final int TYPE_NEW = 0x01;

	public static final int TYPE_RECOMMEND = 0x02;

	/*-----------------------服务器阈值部分-------------------------------*/
	
	public static final int MAX_PLAYERS = 0x06;

	/**
	 * @param decrypt
	 */
	public ServerStatus(byte[] decrypt, int serverId) {
		super(decrypt);

		GameServerInfo gsi = GameServerTable.getInstance().getRegisteredGameServerById(serverId);
		if (gsi != null) {
			int size = readInt();
			for (int i = 0; i < size; i++) {
				int type = readInt();
				int value = readInt();
				switch (type) {
				case SERVER_LIST_STATUS:
					gsi.setStatus(value);
					break;
				case SERVER_LIST_CLOCK:
					gsi.setShowingClock(value == ON);
					break;
				case SERVER_LIST_SQUARE_BRACKET:
					gsi.setShowingBrackets(value == ON);
					break;
				case TEST_SERVER:
					gsi.setTestServer(value == ON);
					break;
				case SERVER_LIST_TYPE:
					gsi.setType(value);
					break;
				case MAX_PLAYERS:
					gsi.setMaxPlayers(value);
					break;
				
				}
			}
		}
	}
}